/**
* Sips Edit settings Page
*
* This page will render the GUI and the Sips settings feilds. This page is
* commented extensively as the sips code is used to base many payment modules
*
* @access 	public
* @author 	Rob
* @copyright	ResMania 2009 all rights reserved.
* @version	1.0
* @link		http://developer.resmania.com/docs:creating_resmania_plugins
* @since  	05-2009
*/

/**
* RM.Pages.Plugin_Sips_Config_Toolbar
*
* Setup the Sips Edit Page toolbar Buttons. This function will render the toolbar
* to the upper right of the GUI. For this page we just need one button to save settings.
*
* @return   ExtJS Panel
*/
RM.Pages.Plugin_Sips_Config_Toolbar = {
    xtype : "panel",
    id : "rm_pages_plugins_sips_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([{image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Admin.Sips.Main.Save, link: "RM.Pages.Functions.plugins_sips_save()"}])
}
RM.Toolbars.push(RM.Pages.Plugin_Sips_Config_Toolbar);

/**
* RM.Pages.Functions.plugins_sips_save
*
*/
RM.Pages.Functions.plugins_sips_save = function(){
    RM.Pages.Plugin_Sips_Panel.getForm().submit({
        params: {
            'id' : Ext.getDom('rm_pages_plugins_sips_id').value,
            'merchant_id' : Ext.getDom('rm_pages_plugins_sips_merchant_id').value,
            'parcom' : Ext.getDom('rm_pages_plugins_sips_parcom').value,
            'cgibin_path' : Ext.getDom('rm_pages_plugins_sips_cgibin_path').value,
            'verified_status' : Ext.getDom('rm_pages_plugins_sips_verified_status').value,
            'invalid_status' : Ext.getDom('rm_pages_plugins_sips_invalid_status').value,
            'version' : Ext.getDom('rm_pages_plugins_sips_version').value,
            'currency_id' : Ext.getDom('rm_pages_plugins_sips_currency_id').value,
            'country' : Ext.getDom('rm_pages_plugins_sips_country').value,
            'payment_means' : Ext.getDom('rm_pages_plugins_sips_payment_means').value,
            'header_flag' : Ext.getDom('rm_pages_plugins_sips_header_flag').value,
            'capture_mode' : Ext.getDom('rm_pages_plugins_sips_capture_mode').value,
            'capture_day' : Ext.getDom('rm_pages_plugins_sips_capture_day').value
        },
        success: function(form, action) {
            RM.Pages.Units_StatusBar = Ext.getCmp('rm_pages_plugins_sips_statusbar');
            RM.Pages.Units_StatusBar.setStatus({
                text: RM.Translate.Admin.Sips.Main.SaveOK,
                iconCls: 'ok-icon'
            });
        },
        failure: function() {
            RM.Pages.Units_StatusBar = Ext.getCmp('rm_pages_plugins_sips_statusbar');
            RM.Pages.Units_StatusBar.setStatus({
                text: RM.Translate.Admin.Sips.Main.SaveFailed,
                iconCls: 'failed-icon'
            });
        },
        waitMsg: RM.Translate.Common.Saving,
        waitTitle: RM.Translate.Common.PleaseWait
    });
}


// the hidden ID feild use to connect this to the DB record.
RM.Pages.Plugin_Sips_ID_Field = new Ext.form.Hidden({
    id : "rm_pages_plugins_sips_id"
});
RM.Pages.Plugin_Sips_MerchantID_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.MerchantID,
    id : "rm_pages_plugins_sips_merchant_id",
    width : 200
});
RM.Pages.Plugin_Sips_Parcom_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.Parcom,
    id : "rm_pages_plugins_sips_parcom",
    width : 200
});
RM.Pages.Plugin_Sips_CGIBinPath_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.CGIBinPath,
    id : "rm_pages_plugins_sips_cgibin_path",
    width : 200
});
RM.Pages.Plugin_Sips_VerifiedStatus_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.VerifiedStatus,
    id : "rm_pages_plugins_sips_verified_status",
    width : 40
});
RM.Pages.Plugin_Sips_InvalidStatus_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.InvalidStatus,
    id : "rm_pages_plugins_sips_invalid_status",
    width : 40
});
RM.Pages.Plugin_Sips_CurrencyID_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.CurrencyID,
    id : "rm_pages_plugins_sips_currency_id",
    width : 40
});
RM.Pages.Plugin_Sips_Country_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.Country,
    id : "rm_pages_plugins_sips_country",
    width : 40
});
RM.Pages.Plugin_Sips_Version_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.SipsVersion,
    id : "rm_pages_plugins_sips_version",
    width : 200
});
RM.Pages.Plugin_Sips_PaymentMeans_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.PaymentMeans,
    id : "rm_pages_plugins_sips_payment_means",
    width : 200
});
RM.Pages.Plugin_Sips_HeaderFlag_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.HeaderFlag,
    id : "rm_pages_plugins_sips_header_flag",
    width : 200
});
RM.Pages.Plugin_Sips_CaptureMode_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.CaptureMode,
    id : "rm_pages_plugins_sips_capture_mode",
    width : 200
});
RM.Pages.Plugin_Sips_CaptureDay_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Sips.Main.CaptureDay,
    id : "rm_pages_plugins_sips_capture_day",
    width : 200
});

// feildset
RM.Pages.Plugin_Sips_Fieldset = new Ext.form.FieldSet({
    id: "rm_pages_plugins_sips_fieldset",
    title: RM.Translate.Admin.Sips.Main.Settings,
    autoHeight: true,
    layout: 'form',
    bodyBorder : false,
    items: [
        RM.Pages.Plugin_Sips_ID_Field,
        RM.Pages.Plugin_Sips_MerchantID_Field,
        RM.Pages.Plugin_Sips_Parcom_Field,
        RM.Pages.Plugin_Sips_CGIBinPath_Field,
        RM.Pages.Plugin_Sips_VerifiedStatus_Field,
        RM.Pages.Plugin_Sips_InvalidStatus_Field,
        RM.Pages.Plugin_Sips_CurrencyID_Field,
        RM.Pages.Plugin_Sips_Country_Field,
        RM.Pages.Plugin_Sips_Version_Field,
        RM.Pages.Plugin_Sips_PaymentMeans_Field,
        RM.Pages.Plugin_Sips_HeaderFlag_Field,
        RM.Pages.Plugin_Sips_CaptureMode_Field,
        RM.Pages.Plugin_Sips_CaptureDay_Field
    ]
});


RM.Pages.Functions.Sips_ConfigJson = function (responseObject) {

    var myMask = new Ext.LoadMask('rm_pages_plugins_sips_main_form', {
        msg: RM.Translate.Common.PleaseWait,
        msgCls: "RM_Loading_Mask_Msg_Hidden" // hide the msg
    });
    myMask.show();

    var settings = responseObject.settings[0];

    // set the values of the form items
    Ext.getCmp("rm_pages_plugins_sips_id").setValue(settings.id);
    Ext.getCmp("rm_pages_plugins_sips_merchant_id").setValue(settings.merchant_id);
    Ext.getCmp("rm_pages_plugins_sips_parcom").setValue(settings.parcom);
    Ext.getCmp("rm_pages_plugins_sips_cgibin_path").setValue(settings.cgibin_path);
    Ext.getCmp("rm_pages_plugins_sips_verified_status").setValue(settings.verified_status);
    Ext.getCmp("rm_pages_plugins_sips_invalid_status").setValue(settings.invalid_status);
    Ext.getCmp("rm_pages_plugins_sips_version").setValue(settings.version);
    Ext.getCmp("rm_pages_plugins_sips_currency_id").setValue(settings.currency_id);
    Ext.getCmp("rm_pages_plugins_sips_country").setValue(settings.country);
    Ext.getCmp("rm_pages_plugins_sips_payment_means").setValue(settings.payment_means);
    Ext.getCmp("rm_pages_plugins_sips_header_flag").setValue(settings.header_flag);
    Ext.getCmp("rm_pages_plugins_sips_capture_mode").setValue(settings.capture_mode);
    Ext.getCmp("rm_pages_plugins_sips_capture_day").setValue(settings.capture_day);

    Ext.getCmp('rm_pages_plugins_sips_main_form').render();
    Ext.getCmp('rm_pages_plugins_sips_main_form').doLayout();

    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_plugins_sips_toolbar');
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_plugins_sips_main_form');

    myMask.hide();

    //RM.Help.Load('Admin.Sips.Edit.Main');

}

// main panel
RM.Pages.Plugin_Sips_Panel = new Ext.FormPanel({
    id : 'rm_pages_plugins_sips_main_form',
    title: RM.Translate.Admin.Sips.Main.Title,
    bodyStyle : "padding:10px;",
    items : [
        RM.Pages.Plugin_Sips_Fieldset
    ],
    url : RM.Common.AssembleURL({
        controller: 'Sips',
        action: 'updateJson'
    }),
    bbar: new Ext.ux.StatusBar({
        id: 'rm_pages_plugins_sips_statusbar',
        items: []
    })
});

RM.Main.Pages.push(RM.Pages.Plugin_Sips_Panel);